﻿using CheatMenu.Utils;
using Fungus;
using Harmony;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace CheatMenu.Patch
{
    public class InstantTextPatcher
    {
        public static bool Enabled { get; set; }

        public static void Patch(HarmonyInstance harmony)
        {
            BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;
            var original = typeof(Writer).GetMethod("ProcessTokens", bindingFlags);
            var prefix = typeof(InstantTextPatcher).GetMethod("prefix_ProcessTokens");
            harmony.Patch(original, new HarmonyMethod(prefix), null);
        }

        public static void prefix_ProcessTokens(Writer __instance)
        {
            if (Enabled)
            {
                ReflectionUtil.SetPunctiationPauseOfWriter(__instance, 0f);
                ReflectionUtil.SetWritingSpeedOfWriter(__instance, 0f);
            }
        }
    }
}
